class Solution
{
public:
    bool _pruneTree(TreeNode *&root)
    {
        if (!root)
            return false;
        bool left_one = _pruneTree(root->left);
        bool right_one = _pruneTree(root->right);
        if (!root->val && !left_one && !right_one)
        {
            root = nullptr;
            return false;
        }
        return root->val | left_one | right_one;
    }
    TreeNode *pruneTree(TreeNode *root)
    {
        if (!root)
            return root;
        _pruneTree(root);
        return root;
    }
};